<html>
<head><meta charset="utf-8"><title>tcp server issue · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html">tcp server issue</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216319579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216319579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216319579">(Nov 11 2020 at 08:49)</a>:</h4>
<p>Hi everyone, I have basic TCP blocking server using <code>std::net::TcpListener</code> and <code>std::net::TcpStream</code> The problem I see is that _sometimes_ the server does not read any bytes from the socket after startup. I see packets are received (using tcptump) and I see the linux socket Rx queue increasing but the application does not read any byte from the socket. I tried different ways to read bytes (<code>read()</code>, <code>buf_fil()</code>, <code>read_exact()</code>) and none of them made a difference. With strace I see the socket is blocked on <code>recvfrom</code>.  I mentioned _sometimes_ before, basically the issue happens once in ~5 tries. Any clue what might be wrong?</p>



<a name="216319684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216319684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216319684">(Nov 11 2020 at 08:50)</a>:</h4>
<p>Can you post your code  somewhere like <a href="http://play.rust-lang.org">play.rust-lang.org</a>?</p>



<a name="216320676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216320676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216320676">(Nov 11 2020 at 09:02)</a>:</h4>
<p>the code looks something like this: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=4fd1de5b1f808dca8e593197f09b38c0">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=4fd1de5b1f808dca8e593197f09b38c0</a></p>



<a name="216320703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216320703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216320703">(Nov 11 2020 at 09:02)</a>:</h4>
<p>I removed the application logic which is mainly involved on<br>
 processing read bytes</p>



<a name="216321090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216321090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216321090">(Nov 11 2020 at 09:06)</a>:</h4>
<p>You're only reading from a client at a time</p>



<a name="216321168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216321168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216321168">(Nov 11 2020 at 09:07)</a>:</h4>
<p>what do you mean? something wrong in the way I use crossbeam scoped threads?</p>



<a name="216321217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216321217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216321217">(Nov 11 2020 at 09:07)</a>:</h4>
<p><code>crossbeam::scope</code> blocks waiting for the threads to finish, so you won't take any new connections while <code>handle_connection</code> is running</p>



<a name="216321358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216321358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216321358">(Nov 11 2020 at 09:08)</a>:</h4>
<p>I only test with one connection and the client connects</p>



<a name="216321511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216321511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216321511">(Nov 11 2020 at 09:10)</a>:</h4>
<p>the reason I am using crossbeam is that I try to share some read only data owned by the main thread with all the threads</p>



<a name="216323430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216323430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216323430">(Nov 11 2020 at 09:30)</a>:</h4>
<p>And there's another bug there, you don't exit when the client disconnects. But I assume it's only in the test code. Can you still reproduce the problem with that simplified example?</p>



<a name="216325616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216325616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216325616">(Nov 11 2020 at 09:55)</a>:</h4>
<p>I need to try the simplified code, will take some time</p>



<a name="216325726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216325726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216325726">(Nov 11 2020 at 09:56)</a>:</h4>
<p>Here is a slightly improved version: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7c0520d91c834ccf619a7a3d074a7d4e">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7c0520d91c834ccf619a7a3d074a7d4e</a></p>



<a name="216348630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216348630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216348630">(Nov 11 2020 at 13:57)</a>:</h4>
<p>seem to work fine now when using the same crossbeam scope, as per your suggestion</p>



<a name="216348652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/tcp%20server%20issue/near/216348652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Maximilian Hristache <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/tcp.20server.20issue.html#216348652">(Nov 11 2020 at 13:57)</a>:</h4>
<p>multumesc frumos :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>